package com.hmyuan.webdesktop.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hmyuan.webdesktop.domain.UserIcon;
import com.hmyuan.webdesktop.service.UserIconService;
import com.hmyuan.webdesktop.util.UserUtil;

@RestController
@RequestMapping("/userIcon")
public class UserIconController {
	@Resource
	UserIconService userIconService;
	
	@RequestMapping("findCanShowList")
	public Map<String, Object> findCanShowList(HttpServletRequest rq,HttpServletResponse rp){
		
		Map<String, Object> result = new HashMap<String, Object>();
		
		List<UserIcon> list = userIconService.findUserIconToShowByUserId(UserUtil.getCurrentUseId(rq));
		result.put("code", 0);
		result.put("msg", "查询成功！");
		result.put("data", list);
		return result;
	}
	@RequestMapping("findList")
	public Map<String, Object> findList(HttpServletRequest rq,HttpServletResponse rp){
		
		Map<String, Object> result = new HashMap<String, Object>();
		
		UserIcon userIcon = new UserIcon();
		userIcon.setUserId(UserUtil.getCurrentUseId(rq));
		List<UserIcon> list = userIconService.findList(userIcon);
		result.put("code", 0);
		result.put("msg", "查询成功！");
		result.put("data", list);
		return result;
	}
	@RequestMapping("update")
	public Map<String, Object> update(HttpServletRequest rq,HttpServletResponse rp,
			UserIcon userIcon){
		Map<String, Object> result = new HashMap<String, Object>();
		if(userIcon.getId()==null) {
			result.put("code", 1);
			result.put("msg", "更新失败！请刷新页面重试！");
		}
		
		userIconService.update(userIcon);
		
		result.put("code", 0);
		result.put("msg", "更新成功！");
		return result;
	}
	@RequestMapping("save")
	public Map<String, Object> save(HttpServletRequest rq,HttpServletResponse rp,
			UserIcon userIcon){
		Map<String, Object> result = new HashMap<String, Object>();
		userIcon.setUserId(UserUtil.getCurrentUseId(rq));
		userIconService.save(userIcon);
		
		result.put("code", 0);
		result.put("msg", "更新成功！");
		return result;
	}
	@RequestMapping("delete")
	public Map<String, Object> delete(HttpServletRequest rq,HttpServletResponse rp,
			Integer id){
		Map<String, Object> result = new HashMap<String, Object>();
		userIconService.deleteById(id);
		
		result.put("code", 0);
		result.put("msg", "更新成功！");
		return result;
	}
}
